extends StateBase


func enter():
	ownerNode.lastMouseHoverMoveableCell = null
	

func exit():
	pass


func run(delta):
	ownerNode.processSelectCell(delta)
	ownerNode.processCamMove(delta)
	processDrawPathHighlight(delta)
	processCancelSelect()
	processConfirmMove()
	
	
func processDrawPathHighlight(delta):
	var mousePositionCell = ownerNode.getMousePositionCell()
	var targetCell = ownerNode.tryFindMoveableCellByCellPos(mousePositionCell)
	if targetCell == null: return
	
	if ownerNode.lastMouseHoverMoveableCell == null or targetCell != ownerNode.lastMouseHoverMoveableCell:
		ownerNode.lastMouseHoverMoveableCell = targetCell
		ownerNode.drawPathHighlight(ownerNode.currentSelectedHeroInst.data.battlePos, targetCell, ownerNode.currentSelectedHeroInst.data.getPropMove())
		

func processCancelSelect():
	if Input.is_action_just_pressed("mouse_right_button"):
		ownerNode.removeWalkableHighlight()
		ownerNode.removePathHighlight()
		ownerNode.deselectHero()
		
		ownerNode.stateMachine.removeState(name)
		ownerNode.stateMachine.addState(Consts.battleFieldStateHeroRoundSelectHero)
		
		
func processConfirmMove():
	if Input.is_action_just_pressed("mouse_left_button"):
		var mousePositionCell = ownerNode.getMousePositionCell()
		var targetCell = ownerNode.tryFindMoveableCellByCellPos(mousePositionCell)
		if targetCell != null:
			ownerNode.currentSelectedHeroInst.processMove(targetCell, ownerNode.onHeroMoveArriveTarget)
			
			ownerNode.removeWalkableHighlight()
			ownerNode.removePathHighlight()
			ownerNode.stateMachine.removeState(name)
			ownerNode.stateMachine.addState(Consts.battleFieldStateHeroRoundHeroMove)
		
	
		

